<template>
	<view class="deivceGoBack">
		<navBar :title="`${titleObj.navTitle}${titleObj.branchLineName ? '(' + titleObj.branchLineName + ')' : ''}`  || ''"></navBar>
		<view class="content required-form-Box">
			<view class="center">
				{{titleObj.subTitle}}
			</view>
			<view class="surface">
				<u-form :model="form" ref="form" :rules="rules" labelPosition="left" labelWidth="auto" class="form"
					:labelStyle="{fontSize: '32rpx', fontWeight: '600',color: '#445469'}">
					<u-form-item label="巡查人员" prop="inspectUser" borderBottom labelWidth="200rpx">
						<view class="required-form-item">*</view>
						<view class="value value-nav">
							<u--input type='text' v-model="form.inspectUser" placeholder="请输入" border="none">
							</u--input>
						</view>
					</u-form-item>
					<u-form-item label="工班归属" prop="shiftOwnership" borderBottom labelWidth="200rpx">
						<view class="value value-nav">
							<u--input type='text' v-model="form.shiftOwnership" placeholder="请输入" border="none">
							</u--input>
						</view>
					</u-form-item>
				</u-form>
			</view>
			<!-- <view class="fixedButton">
				<u-button type="primary" text="开始巡查" @click="fnNavPage"></u-button>
			</view> -->
			
		</view>
		<view class="footer-button">
			<view class="button-placeholder"></view>
			<view class="button-group">
				<button @click="fnNavPage"  class="button-primary">开始巡查</button>
			</view>
		</view>
		<u-loading-page :loading="isLoading"  loading-text="缓存数据中·····" :color="'#3b9cff'" :bgColor="'rgba(0, 0, 0, 0.7)'"></u-loading-page>
	</view>
</template>

<script>
	import mixins from "@/utils/mixins.js"
	import {
		getLastFillingRecord,
		inspectLogUpdateState
	} from '@/api/engineeringMaintenance/engineeringMaintenance.js'
	import {BS, BSM} from '@/session/index.js'
	import {
		pmProcessReportGetDetail
	} from '@/api/comprehensive/comprehensive.js'
	import {
		doGet,
		doSave,
		doDelete
	} from "@/utils/offline/sqlite/index.js";
	//巡检的所有接口
	import * as XUNJIAN from '@/api/engineeringMaintenance/engineeringMaintenance.js'
	// #ifdef APP-PLUS
	import {before} from "@/subpackage-enginner/pages/engineeringMaintenance/common/beforeOffline.js"
	import {networkOnline} from "@/utils/offline/listener.js"
	// #endif
	export default {
		name: 'startPatrolInspection',
		mixins:[mixins],
		data() {
			return {
				isLoading:false,
				form: {
					inspectUser:'',
					shiftOwnership:'',
				},
				rules: {},
				common_params:{},	//dispatch组件带过来的入参
				titleObj:{
					navTitle:'',
					subTitle:''
				}
			}
		},
		onLoad(params) {
			this.common_params = JSON.parse(params.recordParams)
			this.titleObj = JSON.parse(params.titleParams)
			this.getRecord(JSON.parse(uni.getStorageSync('lineData')))
			
		},
		methods: {
			async fnNavPage() {
				if(!this.form.inspectUser) return uni.showToast({
					title:'请填写巡查人员',
					icon:'none'
				})
				// #ifdef APP-PLUS
				if(!(await networkOnline())) {
					uni.showToast({
						title:'获取离线失败',
						icon:'none',
						mask:true,
						success: () => {
							setTimeout(() => {
								uni.navigateBack()
							},1700)
						}
					})
					return
				}
				// #endif
				this.$set(this.common_params, 'inspectUser', this.form.inspectUser)
				this.$set(this.common_params, 'shiftOwnership', this.form.shiftOwnership)
				this.$set(this.common_params, 'inspectDate', new Date().getTime())
				let result = await doSave(XUNJIAN.inspectLogUpdateState,this.common_params)
				BSM[BS.session2].inspectUser = this.form.inspectUser
				//将巡查人员缓存到本地
				// uni.setStorageSync('inspectUser',this.form.inspectUser)
				console.log(this.common_params,'入参',this.titleObj);
				// await before(this.common_params,8)
				// return
				uni.$emit('listenerClickStartBtn', JSON.parse(uni.getStorageSync('lineData')).lineSiteSectionId)
				//离线之前准备工作
				// #ifdef APP-PLUS
					this.isLoading = true
					await before(JSON.parse(uni.getStorageSync('lineData')), {
						projectId:uni.getStorageSync('isOwner')
					})
					this.isLoading = false
				// #endif
				uni.navigateTo({
					url: `/subpackage-enginner/pages/engineeringMaintenance/on_site_inspection/continueToPatrol?titleParams=${JSON.stringify(this.titleObj)}`
				})
			},
			getRecord(obj) {
				// getLastFillingRecord(obj)
				doGet(getLastFillingRecord, obj).then(res => {
					console.log(res, '上次填报')
					if(res.status === 1 && res.success) {
						if(res.result) {
							this.$set(this.form, 'inspectUser', res.result.inspectUser)
							this.$set(this.form, 'shiftOwnership', res.result.shiftOwnership)
						}
					}
				})
			},
		},


	}
</script>

<style lang="scss" scoped>
	.deivceGoBack {
		/* #ifdef MP-WEIXIN */
			padding-top: 190rpx;
		/* #endif */
		.content {
			background-color: #F5F7FA;
			padding-top: 30rpx;

			.center {
				height: 50rpx;
				font-size: 36rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: bold;
				color: #445469;
				line-height: 42rpx;
				background-color: #FFFFFF;
				padding: 48rpx 28rpx;
			}

			.surface {
				background-color: #FFFFFF;
				padding: 0 50rpx;

				.value {
					display: flex;
					align-items: center;
					justify-content: space-between;
				}

				.value-nav {
					position: relative;


				}
			}

		}
	}
	/deep/ .u-button--primary{
		background-color: #2F80ED ;
		border-color: #2F80ED ;
	}
</style>
